package server;

import utli.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class jdbc3 {
    public static void main(String[] args) throws Exception {
        zheng();
        update();
        dalete();
        cha();
    }
    public static void zheng() throws SQLException {
        Connection getconn = DBUtil.getconn();
        String sql = "insert into user valus(?,?,?,?,?)";
        PreparedStatement pr = getconn.prepareStatement(sql);
        pr.setInt(1,3);
        pr.setString(2,"刘崇");
        pr.setString(3,"123456");
        pr.setString(4,"男");
        pr.setString(5,"2001-3-16");
        int i = pr.executeUpdate();
        System.out.println(i);
        pr.close();
        getconn.close();
    }
    public static void update() throws SQLException {
        Connection getconn = DBUtil.getconn();
        String sql = "update user set name = ? where id =?";
        PreparedStatement pr = getconn.prepareStatement(sql);
        pr.setString(1,"hhhh");
        pr.setInt(2,25);
        int resultSet = pr.executeUpdate(sql);
        System.out.println(resultSet);
        pr.close();
        getconn.close();
    }
    public static void dalete() throws SQLException {
        Connection getconn = DBUtil.getconn();
        String sql = "delete from user where id = 1";
        PreparedStatement pr = getconn.prepareStatement(sql);

        int i = pr.executeUpdate();
        pr.close();
        getconn.close();
    }
    public static void cha() throws SQLException {
        Connection getconn = DBUtil.getconn();
        String sql = "select * from user";
        PreparedStatement preparedStatement = getconn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        System.out.println(resultSet);

        preparedStatement.close();
        getconn.close();
    }
}
